<template>
  <div>
    <el-form class="tl-form" ref="form" :model="model" :rules="rules"  label-width="100px">
      <div class="tl-form-line-title" v-if="lastPhase === 1 || lastPhase === 3">
        办理信息
      </div>
      <el-row>
        <el-col :span="12">
          <el-form-item label="问题等级" prop="questionlevel" v-if="lastPhase === 3" :rules="rules.validateRequire">
            <el-select v-model="model.questionlevel" placeholder="请选择问题等级" clearable>
              <el-option v-for="item in codeModel.feedbackQuestionLevelList" :key="item.code" :label="item.name" :value="item.code"/>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="是否公开" prop="ispublic"  v-if="lastPhase === 3" :rules="rules.validateRequire">
            <el-select v-model="model.ispublic" placeholder="请选择是否公开" clearable>
              <el-option v-for="item in codeModel.feedbackIsPublicList" :key="item.code" :label="item.name" :value="item.code"/>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="选择办理人" prop="dealpersonname" v-if="lastPhase === 1" :rules="rules.validateRequire">
            <tl-ref-user v-model="model.dealpersonname" dataType="code" :initDisplayData.sync="model.dealpersonname" :disabled="lastPhase !== 1" :singleSelect="true" @confirm="getDealPerson"></tl-ref-user>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <div class="tl-form-line-title">
          问题描述
        </div>
        <el-col :span="24">
          <el-form-item prop="content" label-width="28px">
            <el-input v-model="model.content" type="textarea" :rows="4" :disabled="true"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row v-if="lastPhase === 3 || lastPhase === 2">
        <div class="tl-form-line-title">
          问题回复
        </div>
        <el-col :span="24">
          <el-form-item label-width="28px">
            <el-scrollbar :style="{ 'max-height': 96 + 'px', 'overflow-x': 'hidden', 'background-color': '#f5f7fa' }">
              <div style="padding: 10px 5px; height: 96px;">
                <div v-if="response.length > 0">
                  <div style="margin-bottom: 10px" v-for="item in response" :key="item.id">
                    <div style="margin-left: 12px;  margin-top: -2px; line-height: 1.5;">回复内容：{{item.dealpersonsuggestion}}</div>
                    <div class="response-time">时间：{{item.createon}}</div>
                  </div>
                </div>
                <div style="margin-left: 12px;  margin-top: -10px;" v-else>暂无回复</div>
              </div>
            </el-scrollbar>
          </el-form-item>
        </el-col>
      </el-row>
      <div class="tl-form-line-title">
        反馈相关
      </div>
      <el-row>
         <el-col :span="12" v-if="this.belongToBpa">
          <el-form-item label="所属业务" prop="belongbusiness">
            <el-select v-model="model.belongbusiness" :disabled="true">
              <el-option v-for="item in codeModel.businessTypeList" :key="item.code" :label="item.name" :value="item.code"/>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12" v-else>
          <el-form-item label="业务类型" prop="servicetype">
            <el-select v-model="model.servicetype" :disabled="true">
              <el-option v-for="item in codeModel.feedbackServiceTypeList" :key="item.code" :label="item.name" :value="item.code"/>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12" v-if="!this.belongToBpa">
          <el-form-item label="所属系统" prop="system">
            <el-select v-model="model.system" :disabled="true">
              <el-option v-for="item in codeModel.feedbackSystemList" :key="item.code" :label="item.name" :value="item.code"/>
            </el-select>
          </el-form-item>
        </el-col>
<!--      </el-row>-->
<!--      <el-row>-->
        <el-col :span="12">
          <el-form-item label="反馈类型" prop="feedbacktype">
            <el-select v-model="model.feedbacktype" :disabled="true">
              <el-option v-for="item in codeModel.feedbackTypeList" :key="item.code" :label="item.name" :value="item.code"/>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="所属负责人" prop="dispsystemperson">
            <el-input v-model="model.dispsystemperson" :disabled="true"></el-input>
          </el-form-item>
        </el-col>
<!--      </el-row>-->
<!--      <el-row>-->
        <el-col :span="12">
          <el-form-item label="反馈人" prop="dispsubmitperson">
            <el-input v-model="model.dispsubmitperson" :disabled="true"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="发生时间" prop="faulttime" v-if="model.faulttime">
            <el-date-picker v-model="model.faulttime" type="datetime" placeholder="请选择发生时间"  value-format="yyyy-MM-dd HH:mm" format=" yyyy-MM-dd HH:mm" :disabled="true"></el-date-picker>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <tl-approval-history ref="history" sourceType="MmsSuggestionFeedback" :sourceId="model.id" />
    <div style="height: 50px; margin-top: 5px;">
      <tl-attachment source-type="MmsSuggestionFeedback" :source-id="model.id" :editable="false" style="float: right;"></tl-attachment>
      <el-button type="primary" @click="$refs.history.visible=true" :disabled="disableApprovalHistory" style="float: right; margin-right: 15px;"><svg-icon icon-class="list" />审批历史</el-button>
    </div>
  </div>
</template>

<script>
/** 子组件 */
/** 工具类 */
import { putAction, getAction, postAction, deleteAction } from '@tapui/utils/http'
import { mixin_list } from '@tapui/mixins/mixin_list'
import { mixin_approval_edit } from '@tapui/mixins/mixin_approval_edit'
import { MMS_SYSTEM_TYPE } from '@/const/const'
/** VUE配置 */
export default {
  mixins: [mixin_approval_edit],
  components: { },
  props: {
    lastPhase: {
      type: Number,
      default: 0
    }
  },
  data() {
    return {
      description: '待审批详情页内嵌组件父组件',
      moduleTitle: '文件申请单',
      urlPrefix: '/mms/suggestionFeedback/',
      url: {
        // 额外的url
        load: '/mms/suggestionFeedback/load',
        edit: '/mms/suggestionFeedback/update',
        queryResponse: '/mms/response/responseList',
        queryCodeList: '/mms/suggestionFeedback/dataCodeList'
      },
      model: {},
      response: [],
      isDisplayButton: false
    }
  },
  computed: {
    /** 判断当前反馈所属系统是否为流程文档 */
    belongToBpa() {
      return this.model && this.model.system && this.model.system === MMS_SYSTEM_TYPE.cdmc
    }
  },
  methods: {
    closeApprovalDialog() {
      this.$emit('closeApprovalDialog')
    },
    // 办理通过前保存修改的信息
    saveInfo(resolve, reject) {
      if (this.lastPhase === 3 && (!this.model.questionlevel || !this.model.ispublic)) {
        this.$tap.alert('请选择问题等级和是否公开', 'warning')
        reject()
      }
      if (this.model.dealperson && this.model.dealperson !== "") {
        putAction(this.url.edit, this.model)
          .then((res) => {
            if (res.success) {
              resolve()
            } else {
              this.$tap.alert(res.message, 'warning')
              reject()
            }
          })
          .catch((err) => {
            this.$tap.alert('保存审批类型信息失败，请联系系统管理员', 'warning')
            reject()
          })
      } else {
        this.$tap.alert('请选择办理人', 'warning')
        reject()
      }
    },
    // 获取处理人参照
    getDealPerson(selectionRow, selectKey, selectionValue) {
      this.$set(this.model, 'dealperson', selectionRow[0].code)
      this.$set(this.model, 'dealpersonname', selectionRow[0].name)
    },
    assignDefaultValue() {
      this.$set(this.model, 'dealperson', this.$store.getters.user.code)
      this.$set(this.model, 'dealpersonname', this.$store.getters.user.name)
    }
  },
  mounted() {
    // this.assignDefaultValue()
  }
}
</script>
<style lang="scss" scoped>
.response-content {
  font-family: '思源黑体 CN', sans-serif;
  font-weight: 400;
  font-style: normal;
  font-size: 13px;
  color: rgba(102, 102, 102, 0.996078431372549);
  line-height: 20px;
}
.response-time {
  font-family: '苹方-简 中等', '苹方-简', sans-serif;
  font-weight: 400;
  font-style: normal;
  font-size: 9px;
  color: #909399;
  height: 15px;
  line-height: 15px;
  vertical-align: middle;
  margin-left: 12px;
}
.text-button {
  font-family: '苹方-简 中等', '苹方-简', sans-serif;
  font-weight: 400;
  font-style: normal;
  font-size: 9px;
  color: #909399;
  height: 15px;
  line-height: 15px;
  vertical-align: middle;
  color: #0A6ED2;
  &:hover {
    cursor: pointer;
  }
}
</style>
